home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / CLOBJECT.CPP < prev    next >
C/C++ Source or Header  |  1995-05-24  |  11KB  |  349 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    clobject.cpp
  5. //   Title:    C++ Class Libraries
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class.
  24. //    This code.
  25. //
  26. //    The code in this module may be written in C++ or C.
  27. //
  28. //    This module is portable to:
  29. //        DOS 3.X+
  30. //        MS Windows 3.X+
  31. //        OS/2 2.X+
  32. //        OS/2 2.0 PM
  33. //
  34. //    The following compilers are supported:
  35. //        MSC 6.0A
  36. //        MSC/C++ 7.0
  37. //        Borland C++ 3.1 for DOS
  38. //        Borland C++ 1.0 for OS/2 2.X
  39. //
  40. //----------------------------------------------------------------------------
  41. #include <class.hpp>
  42.  
  43.  
  44. //----------------------------------------------------------------------------
  45. //   Description:    Default constructor
  46. //    Parameters:
  47. //       Returns:    
  48. //----------------------------------------------------------------------------
  49. FN_M CL_OBJECT::CL_OBJECT()
  50. {
  51.     CL_OBJECT::Initialize(CL_INIT_CLASS);
  52. }
  53.  
  54.  
  55. //----------------------------------------------------------------------------
  56. //   Description:    Copy constructor
  57. //    Parameters:    rccl_object        Reference to object to copy.
  58. //       Returns:    
  59. //----------------------------------------------------------------------------
  60. FN_M CL_OBJECT::CL_OBJECT(RCCL_OBJECT rccl_object)
  61. {
  62.     CL_OBJECT::Initialize(CL_INIT_CLASS);
  63.     *this = rccl_object;
  64. }
  65.  
  66.  
  67. //----------------------------------------------------------------------------
  68. //   Description:    Destructor
  69. //    Parameters:
  70. //       Returns:    
  71. //----------------------------------------------------------------------------
  72. FN_M CL_OBJECT::~CL_OBJECT()
  73. {
  74.     CL_OBJECT::Destroy(FALSE);
  75. }
  76.  
  77.  
  78. //----------------------------------------------------------------------------
  79. //   Description:    Check an object for an error condition and if set, transfer
  80. //                          the error condition to the current object.
  81. //    Parameters:    pcl_object            Object to check.
  82. //       Returns:    IsError().
  83. //----------------------------------------------------------------------------
  84. BOOL FN_M CL_OBJECT::CheckError(PCL_OBJECT pcl_object)
  85. {
  86.     if (pcl_object->IsError())
  87.         SetError(pcl_object->ErrorCode());
  88.  
  89.     return IsError();
  90. }
  91.  
  92.  
  93. //----------------------------------------------------------------------------
  94. //   Description:    Destroy object. Free any resources used by object.
  95. //                          Normally called by destructor.
  96. //                        Should allow multiple calls from various classes.
  97. //    Parameters:    fDestroyAll        Destroy parents also?
  98. //                                            Default is TRUE.
  99. //       Returns:    TRUE if successful.
  100. //----------------------------------------------------------------------------
  101. BOOL FN_M CL_OBJECT::Destroy(BOOL)
  102. {
  103.     CL_OBJECT::Initialize(CL_INIT_CLASS_VARS);
  104.     return TRUE;
  105. }
  106.  
  107.  
  108. //----------------------------------------------------------------------------
  109. //   Description:    
  110. //    Parameters:
  111. //       Returns:    FALSE.
  112. //----------------------------------------------------------------------------
  113. BOOL FN_MV CL_OBJECT::Error_Debug(PCSZ psz, ...)
  114. {
  115.     SetError();
  116.     va_list marker;
  117.     va_start(marker,psz);
  118.     ErrorV_Debug(psz, marker);
  119.     va_end(marker);
  120.     return FALSE;
  121. }
  122.  
  123.  
  124. //----------------------------------------------------------------------------
  125. //   Description:    
  126. //    Parameters:
  127. //       Returns:    FALSE.
  128. //----------------------------------------------------------------------------
  129. BOOL FN_MV CL_OBJECT::ErrorNoMem_Debug(PCSZ pcsz, SIZET cLine)
  130. {
  131.     DebugSetLocation((PSZ)pcsz, cLine);
  132.     Error_Debug(
  133.         "Out of memory.\n"
  134.         "Please increase available system memory and try again.");
  135.     return FALSE;
  136. }
  137.  
  138.  
  139. //----------------------------------------------------------------------------
  140. //   Description:    Initialize object. 
  141. //                          Normally called by constructor.
  142. //                        Should allow multiple calls from various classes.
  143. //    Parameters:    sInit        Initialization code. May be one of the following:
  144. //                                        CL_INIT_CLASS            Reset class variables and
  145. //                                                                    and dynamic allocations for
  146. //                                                                    this class only.
  147. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  148. //                                                                    this class only.
  149. //                                        CL_INIT_VARS            Reset class variables.
  150. //                                        CL_INIT_ALL                Initialize class and all 
  151. //                                                                    parent class, including
  152. //                                                                    dynamic memory allocation.
  153. //                                    Default is CL_INIT_ALL
  154. //       Returns:    TRUE if successful.
  155. //----------------------------------------------------------------------------
  156. BOOL FN_M CL_OBJECT::Initialize(SHORT)
  157. {
  158.     errorCode = ERR_SUCCESS;
  159.     return TRUE;
  160. }
  161.  
  162.  
  163. //----------------------------------------------------------------------------
  164. //   Description:    Assignment operator
  165. //                          NOTE: Don't copy object into self
  166. //    Parameters:    rccl_object        Reference to right value.
  167. //       Returns:    Reference to new object.
  168. //----------------------------------------------------------------------------
  169. RCCL_OBJECT FN_M CL_OBJECT::operator=(RCCL_OBJECT rccl_object)
  170. {
  171.     if (this != &rccl_object)
  172.         {
  173.         if (rccl_object.IsError())
  174.             {
  175.             Destroy();
  176.             SetError(rccl_object.ErrorCode());
  177.             }
  178.         else
  179.             {
  180.             errorCode = rccl_object.errorCode;
  181.             }
  182.         }
  183.     return (RCCL_OBJECT)*this;
  184. }
  185.  
  186.  
  187. //----------------------------------------------------------------------------
  188. //   Description:    Load an object from persistent storage.
  189. //         No error is displayed if the read fails becuase the named
  190. //        data was not found!
  191. //   Parameters:    pcszName        Pointer to name of object.
  192. //        pcszClass    Object class description.
  193. //        ppb            Pointer to variable to receive address of
  194. //                    object. Buffer is dynamically allocated and
  195. //                    must be freed by the caller.
  196. //        pcb            Pointer to variable to receive size of object.
  197. //       Returns:    TRUE if successful.
  198. //----------------------------------------------------------------------------
  199. BOOL FN_M CL_OBJECT::ReadObject(PCSZ pcszName, PCSZ pcszClass, PBYTE _FAR_ *ppb, PSIZET pcb)
  200. {
  201.     Assert(pcszName && ppb);
  202.     if (pcszClass == NULL)
  203.         pcszClass = "";
  204.  
  205.     CL_STRING string("%s%s", pcszName, pcszClass);
  206.     if (string.IsError())
  207.         return FALSE;
  208.  
  209.     if (!CfgFind((PCSZ)string))
  210.         return FALSE;
  211.  
  212.     return CfgRead((PCSZ)string, ppb, pcb);
  213. }
  214.  
  215.  
  216. //----------------------------------------------------------------------------
  217. //   Description:    Retrieve object from persistent storage
  218. //    Parameters:    pcsz        Name of object.
  219. //                        pcszSub    Sub-name of object.
  220. //                                    The first character of the name should be '~'.
  221. //                                    If NULL, no sub name is available.
  222. //                                    Default is NULL
  223. //       Returns:    TRUE if successful.
  224. //----------------------------------------------------------------------------
  225. BOOL FN_M CL_OBJECT::Retrieve(PCSZ pcsz, PCSZ pcszSub)
  226. {
  227.     NOTUSED(pcsz);
  228.     NOTUSED(pcszSub);
  229.     ClearError();
  230.     return TRUE;
  231. }
  232.  
  233.  
  234. //----------------------------------------------------------------------------
  235. //   Description:    Store object to persistent storage
  236. //    Parameters:    pcsz        Name of object.
  237. //                        pcszSub    Sub-name of object.
  238. //                                    The first character of the name should be '~'.
  239. //                                    If NULL, no sub name is available.
  240. //                                    Default is NULL
  241. //       Returns:    TRUE if successful.
  242. //----------------------------------------------------------------------------
  243. BOOL FN_M CL_OBJECT::Store(PCSZ pcsz, PCSZ pcszSub)
  244. {
  245.     NOTUSED(pcsz);                                // Error code is not stored!
  246.     NOTUSED(pcszSub);
  247.     return TRUE;
  248. }
  249.  
  250.  
  251. //----------------------------------------------------------------------------
  252. //   Description:    Save an object to persistent storage.
  253. //    Parameters:    pcszName        Pointer to name of object.
  254. //                        pcszClass    Object class description.
  255. //                        pb                Pointer to object
  256. //                        cb                Size of object.
  257. //       Returns:    TRUE if successful.
  258. //----------------------------------------------------------------------------
  259. BOOL FN_M CL_OBJECT::WriteObject(PCSZ pcszName, PCSZ pcszClass, PBYTE pb, SIZET cb)
  260. {
  261.     Assert(pcszName && pb && cb);
  262.     if (pcszClass == NULL)
  263.         pcszClass = "";
  264.  
  265.     CL_STRING string("%s%s", pcszName, pcszClass);
  266.     if (string.IsError())
  267.         return FALSE;
  268.  
  269.     return CfgWrite((PCSZ)string, pb, cb);
  270. }
  271.  
  272.  
  273. //----------------------------------------------------------------------------
  274. //   Description:    Print object value to debugging output.
  275. //    Parameters:    pccl_object        Pointer to dynamic object. 
  276. //                                    If NULL, static data elements are printed.
  277. //                                    Default is NULL.
  278. //                        pcsz        Name of object.
  279. //                                    If NULL, no name is displayed.
  280. //                                    Default is NULL.
  281. //                        cLevel    Display level. 
  282. //                                    Default is zero.
  283. //       Returns:
  284. //----------------------------------------------------------------------------
  285. #if COMPILE_DEBUG
  286. VOID FN_M CL_OBJECT::Print(PCCL_OBJECT pccl_object, PCSZ pcsz, SIZET cLevel)
  287. {
  288. #if COMPILE_TEST
  289.     OutputL(cLevel, "CL_OBJECT%s%s", (pcsz?"::":""), (pcsz?pcsz:""));
  290.     cLevel++;
  291.     if (pccl_object)
  292.         {
  293.         Output(" <%p>\n", pccl_object);
  294.         OutputL(cLevel, "errorCode = %lu\n", (ULONG)pccl_object->errorCode);
  295.         if (pccl_object->IsError())
  296.             OutputL(cLevel, "Object is in an error state.\n");
  297.         if (!pccl_object->IsValid())
  298.             OutputL(cLevel, "Object is not valid.\n");
  299.         }
  300.     else
  301.         Output(" <NULL>\n");
  302.     return ;
  303. #else
  304.     NOTUSED(cLevel);
  305.     NOTUSED(pccl_object);
  306.     NOTUSED(pcsz);
  307.     return ;
  308. #endif
  309. }
  310. #endif
  311.  
  312.  
  313. //----------------------------------------------------------------------------
  314. //   Description:    Run standard test suite on object.
  315. //    Parameters:    sTest        Test to run.
  316. //                                    If 0, run default tests.
  317. //                                    Default is 0.
  318. //       Returns:    TRUE if successful.
  319. //----------------------------------------------------------------------------
  320. #if COMPILE_DEBUG
  321. BOOL FN_M CL_OBJECT::Test(SHORT sTest)
  322. {
  323. #if COMPILE_TEST
  324.     CL_OBJECT obj1, obj2;
  325.  
  326.     if (sTest == 0 || sTest == 1)
  327.         {
  328.         CL_OBJECT cl_object;
  329.         cl_object.Store("CL_OBJECT");
  330.         cl_object.Retrieve("CL_OBJECT");
  331.         CL_OBJECT::Print(&cl_object);
  332.         }
  333.     if (sTest == 0 || sTest == 2)
  334.         {
  335.         obj1.SetError(5);
  336.         obj2 = obj1;
  337.         CL_OBJECT::Print(&obj2);
  338.         }
  339.     return TRUE;
  340. #else
  341.     NOTUSED(sTest);
  342.     return TRUE;
  343. #endif
  344. }
  345. #endif
  346. //----------------------------------------------------------------------------
  347. //------------------------------- End of File --------------------------------
  348. //----------------------------------------------------------------------------
  349.